home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / ellis / gc4.ps (.svg) < prev    next >
Encapsulated PostScript  |  1993-07-23  |  81KB  |  526x905  |  8-bit (133 colors)
Labels: black | darkness
OCR: onlyaalternativeäsato have the compilergenerateacodeathatanitializesatoannullallapointerarrays createdanasafeblocks.aApointerarray containedavithinanautomaticavariableamust.beazeroedaon entryatoa theavariable's block,andanapointerarray containedavithinanabjectacreated byanewamust bezeroedbyanew.a(Theaanguagealreadyænsures that staticavariablesarea.eroed.) Requiring compilersaoanitialize pointerarraysasallowedbyaheaC++adefinition, which merelyastates that the initialavaluesafavariablesaureaundefined. 7.8.Safearrays Safearraysare provided by three standarda templatealassesadefiningarraysaffixedasize,arraysaf varyingaize allocatedanaheaheap,andasub-arraysaofaheafirstawoakinds.alheapverloadeda subscript operatoraofatheseæclassesæhecksætaun-timeathatatsändexasawithinabounds,asignalingaaun-time errorafannot.alheanterfaceaoathesealassesaisadeclaredasafe,aneaninganyause by clients cannot violate safety, butaheirämplementationsaustauseaunsafedanguage features.aAppendixa provides accompletely specifiedänterfaceandaimplementation. These classesareantended to provide asafe,æfficientalternative to the basic functionality of built-inaC++arrays,anotaheafullagenerality of higher-levelarrayabstractions. Theyavould be specifiedandancludedaspartaofaheastandardaclasses availableavithanyamplementationaofahe safeasubset. Programmersawanting to buildaheir ownaflavorafasafearraysacanauseaheseabothaisan modelandaus building blocks. T AnaArray<T, in>disanarrayaofa ælementsa faypea ahatbehavesaikeabuilt-inaC++array. Foræxample, Array<int, i10>ia; declaresa aobeanarrayaofal Oantegers,an [0] athroughaa [9].aAnaArrayasarepresentedausing the built-in C++aurrayaype: template <classiT, iintin>iclassiArrayi { iiiiTia [n]; iiii...); Aadynamicarray DynArray<T>asapointeraomheap-allocatedarray ofælementsafatypea whoseasizeasachosenawhenahearrayasacreated. Forexample, DynArray<int>idl, id2; dli-iDynArray<int> (100); d2i=iDynArray<int> (200); dlarefersatoanairrayaofal 00antegers,ad [0] ahroughad [99].aADynArrayas representedansan single pointeraomaheap-allocated array: template<claasiT>iclassiDynArrayi ( iiiiT*ia; iiii...); The size ofa DynArrayasastoredbynewawithathearray. AaSubArray<T>actsasaareferenceatomasub-sequence ofælementsananothera Array DynArray,araSubArray.BubArraysarea constructedausingaheaSubanethods ofaheahree classes.Foræxample,afa asanArray<T, in>,a6ubArray<T>,arDynArray<T>,ahen SubArray<T> isi-ia. Sub (start, ilength) initializesa to bemæsub-arrayapfælementsa [start] ahrougha [starti+ilengthi-il] Thealementsæofa ashareastorageavithathealementsofa ;ahatais,as [i] asahe samed valueans a [starti+ii] SubArraysacanbeausedatoapassavarying-sizedarraysabyareference. Considerahisafunction declaration: 31